package com.tcm.portal.web.controller;

import com.base.core.exception.ServiceException;
import com.base.core.utils.R;
import com.tcm.store.domain.dto.StoreServiceDTO;
import com.tcm.store.service.StoreServiceService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/portal")
@RestController
public class StoreServiceController {

    @DubboReference(version = "0.0.1-alpha", check = false, timeout = 3000)
    private StoreServiceService storeServiceService;

    /**
     * 检查某药房是否支持某类型服务
     * @param storeId
     * @return
     */
    @GetMapping("/store/service/check")
    public R checkService(Long storeId, String category, Long dosageId) {
        return R.success(storeServiceService.checkService(storeId, category, dosageId));
    }


    /**
     * 获取药房服务价格
     * @return
     */
    @GetMapping("/store/service/price")
    public R storeServicePrice(Long storeId , String category, Long dosageId) {

        StoreServiceDTO storeServiceDTO;
        try {
            storeServiceDTO = storeServiceService.queryServiceByCategory(storeId, category, dosageId);
        } catch (ServiceException e) {
            return R.fail(e.getResult().getCode(), e.getMessage());
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
        return R.success(storeServiceDTO);

    }


}
